The concept of cleaning of the smart office can be split into two tasks: floor and waste bins. The same procedure is used for both operations. The description in this section contains code snippets from the office region asking the vacuum cleaners for cleaning its floor.

\subsection{Agent: Office region}
The office implemented has four regions. An office region agent has the responsibility of registering how dirty the floor in its region is. If the floor gets too dirty, an OneShotBehaviour called CFPCleanBehaviour is added to the agent, and executed concurrently with the rest of its active behaviours.
Using the code snippet below, the office region searches the yellow pages for agents able to clean the floor.

%code
\lstinputlisting[caption={(Code snippets of) OfficeRegion.java},label={yellow-pages}]{Codes/OfficeYellowPages.java}
%end code

Using setType(..)-method in a ServiceDescription-object the office region is able to describe which type of service it is looking for. When the needed service is added to a DFAgentDescription-object, the office region can request a search in the yellow pages, for agents providing the desired service. For each of the agents found in the yellow pages the code below is executed.

%code
\lstinputlisting[caption={(Code snippets of) OfficeRegion.java},label={office-cfp}]{Codes/OfficeCFP.java}
%end code

To each of the agents found in the yellow pages a message with the performative CFP (Call for Proposal) is send, using the local name of the agent on the agent platform. Using the ontology a message with the type CALL\_CLEAN is constructed. The last thing CFPCleanBehaviour does before it terminates is to add a new OneShotBehaviour called ChooseVacuumCleanerBehaviour to the OfficeRegion agent.
The execution ChooseVacuumCleanerBehaviour starts by sleeping for a short while. In the mean time the vacuum cleaner agents have had some time to return their answers, maybe with a PROPOSE message. The names of all vacuum cleaners proposing to do the task are added to a collection where their speed is registered as well. ChooseVacuumCleanerBehaviour traverses the collection, and to the vacuum cleaner found most suitable to do the task an ACCEPT\_PROPOSAL message is send.

%code
\lstinputlisting[caption={(Code snippets of) OfficeRegion.java},label={office-accept}]{Codes/OfficeAccept.java}
%end code

\subsection{Agent: Vacuum cleaner}

When a vacuum cleaner agent receives a CPF the code below is accessed.

%code
\lstinputlisting[caption={(Code snippets of) VacuumCleaner.java},label={cleaner-cfp}]{Codes/CleanerCFP.java}
%end code

The vacuum cleaner checks if it is IDLE, and thereby able to do the task. If it is IDLE, then it calculates the time it needs to do the task, and the information is returned in a PROPOSE message to the asking office region. When an office region has accepted a proposal, the vacuum cleaner agent changes its status to VACUUMING and a boolean called clean is set to true.

%code
\lstinputlisting[caption={(Code snippets of) VacuumCleaner.java},label={cleaner-accepted}]{Codes/CleanerAccepted.java}
%end code

The clean boolean is used in a TickerBehaviour called CleanFloorBehaviour. This behaviour almost functions as a state machine, at all times at keeps track of the state of the vacuum cleaner, and notices other agents with information when needed. The code below summarizes what happens in the different states. The actual code is not shown because it uses too much space.

%code
\lstinputlisting[caption={(Code snippets of) VacuumCleaner.java},label={cleaner-clean}]{Codes/CleanerCleaning.java}
%end code

This concludes the documentation of how the cleaning part of the system is implemented.
 \figureref{implementation-figure-sniffer1} and \figureref{implementation-figure-sniffer2} is a screenshot of the Jade sniffer showing how the implemented agents actually communicates with each other.

%figures
\begin{figure}[H]
  \begin{center}
    \includegraphics[trim=0mm 0mm 0mm 0mm, clip, scale=1.0]{Images/Implementation/SNIFFER1.png}
    \caption{Screenshot of Sniffer agent sniffing the communication between OfficeRegion and VacuumCleaner}
    \label{implementation-figure-sniffer1}
  \end{center}
\end{figure}
\begin{figure}[H]
  \begin{center}
    \includegraphics[trim=0mm 0mm 0mm 0mm, clip, scale=1.0]{Images/Implementation/SNIFFER2.png}
    \caption{Screenshot of Sniffer agent sniffing the communication between OfficeRegion and VacuumCleaner}
    \label{implementation-figure-sniffer2}
  \end{center}
\end{figure}

The two screen shots show that an office region agent requests the yellow pages for the vacuum cleaners. Then it sends out a CFP to each of the present vacuum cleaners, and depending on the vacuum cleaners, they chose to send a PROPOSAL or not in return to the office region. The office region evaluates the proposals, and accepts one of them. Finally the chosen vacuum cleaner starts to do the cleaning. 